#include "config.h"

#include "ms2sim.h"

ECMBOOL	is_stat_started;
ECMBOOL	is_stat_from_start;
ecm_uint64	ts_stat_start;
ecm_uint32	stat_duration;

static ecm_uint64	ts_advance = 1000000;	/* 1 sec */
static ecm_uint64	ts_next;

ecm_uint64
probe_stat_system(ecm_uint64 ts)
{
	return ts_next;
}

void
schedule_stat_system(ecm_uint64 ts)
{
	ECMASSERT(ts_next == ts);

	is_stat_started = ECM_TRUE;

	check_session_stats(ts);
	check_media_stats();
	check_request_stats();
	check_disk_stats();
	check_network_stats();
	check_bcache_stats();

	ts_next += ts_advance;
}

ECMBOOL
init_stat(void)
{
	if (is_stat_from_start) {
		ts_next = 1000000;
		is_stat_started = ECM_TRUE;
		stat_duration = duration;
	}
	else {
		if (max_media_length * 2 >= duration) {
			ERR("Simulation duration is too short. Duration should be larger than %s.",
			    msl_get_duration_str(max_media_length * 2));
			ERR("Or enable stat_from_start");
			return ECM_FALSE;
		}

		ts_stat_start = ts_next = (ecm_uint64)max_media_length * 2 * 1000000;
		stat_duration = duration - max_media_length;
	}

	return ECM_TRUE;
}
